<template>
  <div class="h287">
    <div
      class="s-tac s-d-flex s-ai-center s-jc-center h287"
      v-if="dataListShow"
    >
      <div>
        <img
          class="w190 h120"
          src="@/assets/nodata.png"
          alt=""
        />
        <div
          style="color: #a8a8a8"
          class="fz14"
        >暂无数据</div>
      </div>
    </div>
    <div v-else>

      <el-table
        :data="tableData"
        style="width: 100%"
      >
        <el-table-column
          prop="hospitalDepartName"
          label="交接科室"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          width="200"
          label="交接时间"
        >
        </el-table-column>
        <el-table-column
          prop="handUserStaffName"
          label="交接人员"
        >
        </el-table-column>
        <el-table-column
          prop="wasteClassifyName"
          width="120"
          label="医废种类"
        >
        </el-table-column>
        <el-table-column
          prop="weight"
          header-align="right"
          align="right"
          width="120"
          label="重量"
        >
          <template v-slot="scope">
            {{ `${scope.row.weight ? scope.row.weight : 0}kg` }}
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import * as statisticsApi from "@/api/statistics";
export default {
  data() {
    return {
      tableData: [],
      dataListShow: false,
    };
  },
  created() {
    this.handleInit();
  },
  methods: {
    handleInit() {
      let params = {
        pageSize: 5,
        pageIndex: 1,
      };
      statisticsApi.collectList(params).then((res) => {
        if (res && res.success) {
          if (res.data && res.data.length != 0) {
            this.dataListShow = false;
          } else {
            this.dataListShow = true;
            return;
          }
          this.tableData = res.data.map((item) => {
            item.createTime = this.timeFormat(item.createTime,'yyyy-mm-dd HH:mm');
            return item
          });
        }
      });
    },
    timeFormat(value, format) {
      if (!value) return;
      let date = new Date(value);
      let y = date.getFullYear();
      let m = date.getMonth() + 1;
      let d = date.getDate();
      let h = date.getHours();
      let min = date.getMinutes();
      let s = date.getSeconds();
      let result = "";
      if (format == undefined) {
        result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${
          h < 10 ? "0" + h : h
        }:${min < 10 ? "0" + min : min}:${s < 10 ? "0" + s : s}`;
      }
      if (format == "yyyy-mm-dd") {
        result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}`;
      }
      if (format == "yyyy-mm-dd HH:mm") {
        result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${
          h < 10 ? "0" + h : h
        }:${min < 10 ? "0" + min : min}`;
      }
      if (format == "yyyy/mm/dd") {
        result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}`;
      }
      if (format == "yyyy-mm") {
        result = `${y}-${m < 10 ? "0" + m : m}`;
      }
      if (format == "mm-dd") {
        result = ` ${mm < 10 ? "0" + mm : mm}:${ddmin < 10 ? "0" + dd : dd}`;
      }
      if (format == "hh:mm") {
        result = ` ${h < 10 ? "0" + h : h}:${min < 10 ? "0" + min : min}`;
      }
      if (format == "yyyy") {
        result = `${y}`;
      }
      return result;
    },
  },
};
</script>